<?php

require_once dirname(dirname(__FILE__)) . '/config/config.php';
require_once DOCUMENT_ROOT . DIR_SHARED_CONFIG . 'connection.php';


class dao_transaction_action {

    //Methods
    public function __construct() {

    }

    public function get_all() {
        $db = new connection();
        $con = $db->open_connect();
        
        $query = "SELECT * "
                . "FROM tbl_transaction_action ";
        $result = mysqli_query($con, $query)
        or die("Query fail: " . mysqli_error());
        
        $list = array();
        while ($row = mysqli_fetch_array($result)) {
            array_push($list, $row);
        }
        $db->close_connect();
        return $list;
    }

//    public function save($id, $user_id, $ticket_id, 
//                $ticket_quantity_solve, $coupon_id, $combo_id, 
//                $combo_quantity_solve, $total_money) {
//        $db = new connection();
//        $con = $db->open_connect();
//        
//        if ($id == 0) {
//            $query = "INSERT INTO tbl_transaction_action(user_id, ticket_id, ticket_quantity, coupon_id, combo_id, combo_quantity, total_money) VALUES (
//                " . $user_id . "," . $ticket_id . "," . $ticket_quantity_solve . "," . $coupon_id . "," . $combo_id . "," . $combo_quantity_solve . "," . $total_money . ")";
//        } else {
//            $query = "UPDATE tbl_transaction_action SET "
//                    . "user_id = '" . $user_id . "',"
//                    . "ticket_id = " . $ticket_id . ","
//                    . "ticket_quantity = '" . $ticket_quantity_solve . "',"
//                    . "coupon_id = '" . $coupon_id . "',"
//                    . "combo_id = '" . $combo_id . "',"
//                    . "combo_quantity = '" . $combo_quantity_solve . "',"
//                    . "total_money = '" . $total_money . "' "
//                    . "WHERE id = " . $id;
//        }
//        mysqli_query($con, $query) or die("Query fail: " . mysqli_error());
//
//        $db->close_connect();
//        return TRUE;
//    }

    public function get_by_id($id) {
        $db = new connection();
        $con = $db->open_connect();

        $query = "SELECT * "
                . "FROM tbl_transaction_action "
                . "WHERE id = " . $id;
        $result = mysqli_query($con, $query) or die("Query fail: " . mysqli_error());

        $row = mysqli_fetch_array($result);

        $db->close_connect();
        return $row;
    }

    public function delete($id) {
        $db = new connection();
        $con = $db->open_connect();

        $query = "DELETE FROM tbl_transaction_action WHERE id = " . $id;
        mysqli_query($con, $query) or die("Query fail: " . mysqli_error());

        $db->close_connect();
        return TRUE;
    }
    

}
